package com.weixiaodong.ModelDesign.交给子类.TemplateMethod模式.练习.Java中IO包下的InputStream使用了模版模式;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

/**
 * java.io.InputStream中使用了模版模式
 *
 * InputStream本身是一个抽象类
 *      public abstract class InputStream implements Closeable
 *
 * InputStream抽象类中最重要的接口：
 *      public abstract int read() throws IOException;
 *
 * 在抽象类内部就封装了读取文件的细节：
 *      public int read(byte b[], int off, int len) throws IOException {
 *         if (b == null) {
 *             throw new NullPointerException();
 *         } else if (off < 0 || len < 0 || len > b.length - off) {
 *             throw new IndexOutOfBoundsException();
 *         } else if (len == 0) {
 *             return 0;
 *         }
 *
 *         int c = read();
 *         if (c == -1) {
 *             return -1;
 *         }
 *         b[off] = (byte)c;
 *
 *         int i = 1;
 *         try {
 *             for (; i < len ; i++) {
 *                 c = read();
 *                 if (c == -1) {
 *                     break;
 *                 }
 *                 b[off + i] = (byte)c;
 *             }
 *         } catch (IOException ee) {
 *         }
 *         return i;
 *     }
 */
public class Main {
    public static void main(String[] args) throws FileNotFoundException {
        InputStream is = new FileInputStream("");
    }
}
